package com.zbf.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonAlias;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;

@RestController
public class TestController {

    @Autowired
    private OkHttpClient  okHttpClient;

    @RequestMapping("test01")
    public void test01(MultipartFile multipartFile, HttpServletResponse response) throws IOException {

        Timer timer=new Timer();



        String templateName="C:\\Users\\lenovo\\Desktop\\模板.xlsx";
        VedioDataListener vedioDataListener = new VedioDataListener(okHttpClient);
        EasyExcel.read(multipartFile.getInputStream(), VedioData.class, vedioDataListener).sheet(0).sheetName("全国视频发布").headRowNumber(2).doRead();
        String fileName = URLEncoder.encode("中文", "UTF-8");
        //响应类型,编码
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        //设置文件的名称
        response.setHeader("Content-Disposition", "attachment; filename=Zjlryshz.xlsx");
        //获取输出流
        ServletOutputStream outputStream = response.getOutputStream();
        //
        EasyExcel.write(outputStream, VedioData.class).needHead(false).excelType(ExcelTypeEnum.XLSX).withTemplate(templateName).sheet("全国视频发布").doWrite(vedioDataListener.getList());


    }

}
